package com.jiyongjun.bms.tool.system;

import com.jiyongjun.bms.tool.exception.BizException;
import lombok.extern.slf4j.Slf4j;

import java.lang.management.RuntimeMXBean;

/**
 * <h2></h2>
 * description:
 *
 * @author yongjun.ji
 * @since 1.0 2019/5/30
 */
@Slf4j
public class JvmUtils {
    public static String getPID() {
        try {
            RuntimeMXBean runtime = java.lang.management.ManagementFactory.getRuntimeMXBean();
            // format: "pid@hostname"
            String name = runtime.getName();
            return name.substring(0, name.indexOf('@'));
        } catch (Throwable t) {
            throw new BizException("JVM PID获取异常", t);
        }
    }
}
